package com.sq.partner.manager.dao.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sq.partner.manager.dao.AdjSoaResultDao;
import com.sq.partner.manager.mybatis.model.AdjSoaResult;
import com.sq.partner.manager.util.Page;
@Repository
public class AdjSoaResultDaoImpl extends BaseDaoImpl implements AdjSoaResultDao{

	@Override
	public Page<AdjSoaResult> queryRecCheckList(int current, int size, String checkDate, String checkType,String isExc) throws Exception {
		Map<String,Object> paramMap = new HashMap<String, Object>();
		int BEGINROW;
		int ENDROW;
		if(current > 1){
			BEGINROW = (current-1) * size;
			ENDROW = current * size - 1;
		}else {
			BEGINROW = 0;
			ENDROW = size;
		}
		paramMap.put("BEGINROW", BEGINROW);
		paramMap.put("ENDROW", ENDROW);
		if(checkDate.length() != 10){
			paramMap.put("batchDate", "%");
		}else {
			paramMap.put("batchDate", checkDate);
		}
		
		if("1".equals(checkType) || "2".equals(checkType)){
			paramMap.put("type", checkType);
		}else {
			paramMap.put("type", "%");
		}
		//本次的查询条件
		Map<String,Object> queryMap = new HashMap<String, Object>();
		queryMap.put("current",current);
		queryMap.put("size",size);
		queryMap.put("checkDate",checkDate);
		queryMap.put("checkType",checkType);
		Integer count = (Integer)this.query("queryAdjSoaResultCountByPage", paramMap);
		Page<AdjSoaResult> page = new Page<AdjSoaResult>(current,count,size);		
		if ("true".equals(isExc) && "".equals(checkDate)) {
			ENDROW = count;
			paramMap.put("ENDROW", ENDROW);
		}
		List<AdjSoaResult> rsList = queryList("queryAdjSoaResultByPage", paramMap);
		//整理查询结果
		for(AdjSoaResult rs : rsList){
			//类型转中文
			if("1".equals(rs.getType())){
				rs.setType("承保");
			}else {
				rs.setType("理赔");
			}
			
			if("1".equals(rs.getSign())){
				rs.setSign("成功");
			}else {
				rs.setSign("失败");
			}
		}
		page.setData(rsList);
		page.setMap(queryMap);
		return page;
	}

	@Override
	public Page<AdjSoaResult> queryRecCheckListAll(String checkDate, String checkType) throws Exception {
		Page<AdjSoaResult> page = new Page<AdjSoaResult>();
		Map<String,Object> paramMap = new HashMap<String, Object>();
		if(checkDate.length() != 10){
			paramMap.put("batchDate", "%");
		}else {
			paramMap.put("batchDate", checkDate);
		}

		if("1".equals(checkType) || "2".equals(checkType)){
			paramMap.put("type", checkType);
		}else {
			paramMap.put("type", "%");
		}
		//本次的查询条件
		Map<String,Object> queryMap = new HashMap<String, Object>();
		queryMap.put("checkDate",checkDate);
		queryMap.put("checkType",checkType);
		Integer count = (Integer)this.query("queryAdjSoaResultCountByPage", paramMap);

		List<AdjSoaResult> rsList = queryList("queryAdjSoaResultByPage", paramMap);
		//整理查询结果
		for(AdjSoaResult rs : rsList){
			//类型转中文
			if("1".equals(rs.getType())){
				rs.setType("承保");
			}else {
				rs.setType("理赔");
			}

			if("1".equals(rs.getSign())){
				rs.setSign("成功");
			}else {
				rs.setSign("失败");
			}
		}
		page.setData(rsList);
		page.setMap(queryMap);
		return page;
	}

}
